$(function () {
    initEditor()
    getCateList()


    function getCateList() {
        axios({
            method: 'GET',
            url: '/my/cate/list'
        }).then(function (res) {
            if (res.data.code !== 0) {
                return layui.layer.msg('分类数据获取失败')
            }
            var list = []
            res.data.data.forEach(function (item) {
                list.push(`
                    <option value="${item.id}">${item.cate_name}</option>
                `)
            })
            $('#selectCate').append(list)
            layui.form.render('select')
        })
    }


    $('.content').attr('disabled', true)


    var PhoneId = getQuery('id')
    if (PhoneId) {
        axios({
            method: 'GET',
            url: '/my/article/info',
            params: {
                id: PhoneId
            }
        }).then(function (res) {
            if (res.data.code !== 0) {
                return layui.msg('文章数据获取失败')
            }

            var { title, cate_id, cover_img, content, id } = res.data.data

            layui.form.val("phone-edit", {
                "cate_id": cate_id,
                "title": title,
                "content": content,
                "id": id
            })

            $('#image').prop('src', `http://www.liulongbin.top:3008${cover_img}`)

            layui.form.render()
        })
    }

    $('#Ph_pub').on('submit', function (e) {
        e.preventDefault()
        location.href = `/Phone/Phlist.html`
    })

})
function getQuery(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)")
    var r = window.location.search.substr(1).match(reg)
    if (r != null) return unescape(r[2])
    return null
}